<?
session_start();
$fp = fopen( 'logUL.txt.html' , 'w+' );
ob_start();
echo "<pre>";

print_r( $_POST );
print_r( $_GET );
print_r( $_SESSION );
print_r( $_FILES );


$upload_dir = $_SESSION['user']['filePath'].$_GET[ 'tmpPath' ];






//foreach ($_FILES["file"]["error"] as $key => $error) 
//if( false )
{
   // if ($error == UPLOAD_ERR_OK) 
	{
        $tmp_name = $_FILES["file"]["tmp_name"];
        $name = $_FILES["file"]["name"];
        move_uploaded_file($tmp_name, $upload_dir."ORIG/".$name);
    }
}



// File and new size
$filename = $upload_dir."ORIG/".$name;


// Content type


// Get new sizes
list($width, $height) = getimagesize($filename);


$percent = 1;

switch( $_GET[ 'tmpPath' ] ){

	case 'logo/':
		$percent = 50 / $height;
	break;
	case 'TB_Texture':

	break;
	case 'M_Texture':

	break;
	case 'BB_Texture':

	break;
	case 'BB_butRef':

	break;
	case 'BB_butInfo':

	break;
	

}



$newwidth = floor( $width * $percent );
$newheight = floor(  $height * $percent );

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);


switch( strrev( substr( strrev( $name ) , 0 , strpos( strrev( $name ), "." ) ) ) ){
case "jpg":
case "jpeg":
	$source = imagecreatefromjpeg($filename);
	function fct_out( $img , $dir ){ imagejpeg($img , $dir ); }
	break;
case "png":
	$source = imagecreatefrompng($filename);
	
	$transparent = imagecolorallocatealpha( $thumb, 0, 0, 0, 127 ); 
	imagefill( $thumb, 0, 0, $transparent ); 
	function fct_out( $img , $dir ){ imagealphablending($img, false);imagesavealpha($img, true);imagepng($img , $dir ); }
break;
case "gif":
	$source = imagecreatefromgif($filename);
	function fct_out( $img , $dir ){ imagegif($img , $dir ); }

break;


}


// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
echo  $newwidth .",". $newheight.",". $width.",". $height."<hr>";
// Output

fct_out($thumb , $upload_dir.$name );






$out = ob_get_contents();
ob_end_flush();
fwrite( $fp , $out );

?>